﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Simple.Common.Core.Log
{
    /// <summary>
    /// 在AssemblyInfo.cs 加 [assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]
    /// </summary>
    public class SimpleLogHelper
    {
        private static readonly log4net.ILog loginfo = log4net.LogManager.GetLogger(typeof(SimpleLogHelper).Name);   //选择<logger name="loginfo">的配置 

        /// <summary>
        /// 写系统信息日志
        /// </summary>
        /// <param name="info"></param>
        public static void Info(string info)
        {
            if (loginfo.IsInfoEnabled)
                loginfo.Info(info);
        }

        /// <summary>
        /// 写错误日志
        /// </summary>
        /// <param name="Error"></param>
        /// <param name="se"></param>
        public static void Error(string msg, Exception ex)
        {
            if (loginfo.IsErrorEnabled)
                loginfo.Error(msg, ex);
        }

        /// <summary>
        /// 记录调试日志
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="ex"></param>
        public static void Debug(string msg, Exception ex = null)
        {
            if (loginfo.IsDebugEnabled)
            {
                if (ex == null)
                {
                    loginfo.Debug(msg);
                }
                else
                {
                    loginfo.Debug(msg, ex);
                }
            }
        }

    }
}
